/*
Copyright (c) [2019年5月1日] [吴超]
[MBT_studio] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
		 http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
#pragma once

#include <向量.h>
#include <omp.h>


typedef void* (*f_线程运行函数指针)(void*);
typedef struct {
	uvec2 range;
	void* data;
}S_线程参数;


class C_线程池 {
	uint32	m_线程数;
	uvec2	m_区间;

	uint32	m_数量;
	uint32	m_区间跨度;

	//std::vector<std::thread>	m_线程;
	std::vector<S_线程参数>	m_线程参数;
	//vector<pthread_t>	m_线程c;

public:
	C_线程池(uint32 range, uint32 线程数=16, f_线程运行函数指针 p=0);
	~C_线程池();

	
	template<typename T>
	void f_运行(const T& fun) {
		/*uvec2 range = m_区间;
		for (uint32 i = 0; i < m_线程数; ++i) {
			if (range.y > m_数量) range.y = m_数量;

			fun(m_线程[i], range, i);

			if (range.y >= m_数量) break;

			range.x += m_区间跨度;
			range.y += m_区间跨度;
		}*/
	}
	void f_等待() {
		/*for (auto& t : m_线程) {
			auto id = t.native_handle();
			if (id) t.join();
		}*/
	}

	void f_运行(f_线程运行函数指针 fun, void* 线程参数);
	void f_等待c();

};


typedef struct {
	clock_t	m_时间start;
	clock_t	m_时间end;
	float32 m_时间间隔;
}S_时间摆;

S_时间摆*	f_time_创建摆(float32 时间间隔);
void		f_time_销毁摆(S_时间摆* 摆);
bool		f_time_摆(S_时间摆* 摆);





